import Vue from "vue";
import Router from "vue-router";
import Home from "@/views/home";
import Login from "@/components/login";

import Layout from "@/layout/index";
import { test } from "shelljs";

Vue.use(Router);
// 解决重复报错问题
const RouterPush = Router.prototype.push;
Router.prototype.push = function push(to) {
  return RouterPush.call(this, to).catch(err => err);
};
const RouterReplace = Router.prototype.replace;
Router.prototype.replace = function replace(to) {
  return RouterReplace.call(this, to).catch(err => err);
};

let originRoutes = [
  {
    path: "/login/:com?",
    name: "login",
    component: Login,
    meta: {
      keepAlive: false,
      title: "登录"
    }
  },

  {
    path: "/",
    name: "home",
    component: Layout,
    meta: {
      keepAlive: false,
      requireAuth: true
    },
    children: [
      {
        path: "/home",
        name: "home-index",
        component: Home
      },
      // 个人信息管理
      {
        path: "/authority/user/details",
        name: "profile",
        component: () => import("@/views/authority/user/details"),
        meta: {
          title: "个人信息管理",
          requireAuth: true
        }
      }
    ]
  },
  // 客户管理
  {
    path: "/custom",
    name: "custom",
    redirect: "/custom/supplier",
    component: Layout,
    meta: {
      title: "客户管理"
    },
    children: [
      {
        path: "/custom/supplier",
        name: "supplier-index",
        component: () => import("@/views/custom/supplier/index"),
        meta: {
          keepAlive: true,
          title: "供应商客户管理",
          requireAuth: true
        }
      },
      {
        path: "/custom/supplier/detailed",
        name: "supplier-index-detailed",
        redirect: "/custom/supplier/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          keepAlive: false,
          title: "供应商客户管理",
          requireAuth: true
        },
        children: [
          {
            path: "/custom/supplier/details",
            name: "supplier-index-details",
            component: () => import("@/views/custom/supplier/details"),
            meta: {
              title: "供应商客户详情",
              requireAuth: true
            }
          }
        ]
      },
      {
        path: "/custom/importer",
        name: "importer-index",
        component: () => import("@/views/custom/importer/index"),
        meta: {
          keepAlive: true,
          title: "进口商客户管理",
          requireAuth: true
        }
      },
      {
        path: "/custom/importer/detailed",
        name: "importer-index-detailed",
        redirect: "/custom/importer/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          title: "进口商客户管理",
          requireAuth: true
        },
        children: [
          {
            path: "/custom/importer/details",
            name: "importer-index-details",
            component: () => import("@/views/custom/importer/details"),
            meta: {
              keepAlive: false,
              title: "进口商客户详情",
              requireAuth: true
            }
          }
        ]
      },
      {
        path: "/member/setting",
        name: "setting-index",
        component: () => import("@/views/member/setting/index"),
        meta: {
          keepAlive: false,
          title: "会员配置",
          requireAuth: true
        }
      },
      {
        path: "/member/supplier",
        name: "setting-index",
        component: () => import("@/views/member/supplier/index"),
        meta: {
          keepAlive: true,
          title: "供应商会员",
          requireAuth: true
        }
      }
    ]
  },
  //授信管理
  {
    path: "/credit",
    name: "credit",
    redirect: "/credit/financial",
    component: Layout,
    meta: {
      title: "授信管理"
    },
    children: [
      {
        path: "/credit/financial",
        name: "financial-index",
        component: () => import("@/views/credit/financial/index"),
        meta: {
          keepAlive: false,
          title: "金融配置",
          requireAuth: true
        }
      },
      {
        path: "/credit/creditApply",
        name: "creditApply-index",
        component: () => import("@/views/credit/creditApply/index"),
        meta: {
          keepAlive: true,
          title: "供应商授信申请",
          requireAuth: true
        }
      },
      {
        path: "/credit/creditApply/detailed",
        name: "creditApply-detailed",
        redirect: "/credit/creditApply",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          title: "供应商授信申请",
          requireAuth: true
        },
        children: [
          {
            path: "/credit/creditApply/details",
            name: "creditApply-details",
            component: () => import("@/views/credit/creditApply/details"),
            meta: {
              title: "授信详情",
              requireAuth: true
            }
          }
        ]
      },

      {
        path: "/credit/bankCredit",
        name: "creditApply-bankCredit",
        component: () => import("@/views/credit/creditApply/bank"),
        meta: {
          keepAlive: true,
          title: "银行授信管理",
          requireAuth: true
        }
      },
      {
        path: "/credit/bankCredit/detailed",
        name: "bankCredit-detailed",
        redirect: "/credit/bankCredit",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          title: "银行授信管理",
          requireAuth: true
        },
        children: [
          {
            path: "/credit/creditApply/bankCredit/details",
            name: "bankCredit-details",
            component: () => import("@/views/credit/creditApply/details"),
            meta: {
              title: "授信详情",
              requireAuth: true
            }
          }
        ]
      }
    ]
  },
  //仓库管理
  {
    path: "/warehouse",
    component: Layout,
    redirect: "/warehouse/index",
    meta: {
      title: "仓库管理",
      requireAuth: true
    },
    children: [
      {
        path: "/warehouse",
        name: "warehouse-index",
        component: () => import("@/views/warehouse/index"),
        meta: {
          keepAlive: true,
          title: "仓库管理",
          requireAuth: true
        }
      },
      //   {
      //     path: "/management",
      //     name: "warehouse-management",
      //     component: () => import("@/views/warehouse/management"),
      //     meta: {
      //       title: "国内仓库管理",
      //       requireAuth: true
      //     }
      //   },
      //   {
      //     path: "/management/detailed",
      //     name: "management-detailed",
      //     redirect: "/warehouse/management/detailed",
      //     component: {
      //       render(c) {
      //         return c("router-view");
      //       }
      //     },
      //     meta: {
      //       title: "国内仓库管理",
      //       requireAuth: true
      //     },
      //     children: [
      //       {
      //         path: "/warehouse/details",
      //         name: "management-details",
      //         component: () => import("@/views/warehouse/details"),
      //         meta: {
      //           title: "仓库详情",
      //           requireAuth: true
      //         }
      //       }
      //     ]
      //   },
      {
        path: "/warehouse/warehousing",
        name: "warehousing-index",
        component: () => import("@/views/warehouse/warehousing/index"),
        meta: {
          keepAlive: true,
          title: "入库管理",
          requireAuth: true
        }
      },
      {
        path: "/warehouse/warehousing/detailed",
        name: "warehousing-detailed",
        redirect: "/warehouse/warehousing/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          title: "入库管理",
          requireAuth: true
        },
        children: [
          {
            path: "/warehouse/warehousing/details",
            name: "warehousing-details",
            component: () => import("@/views/warehouse/warehousing/details"),
            meta: {
              title: "入库管理详情",
              requireAuth: true
            }
          }
        ]
      },
      {
        path: "/warehouse/in-warehouse",
        name: "in-warehouse-index",
        component: () => import("@/views/warehouse/in-warehouse/index"),
        meta: {
          keepAlive: true,
          title: "在库管理",
          requireAuth: true
        }
      },
      {
        path: "/warehouse/in-warehouse/detailed",
        name: "in-warehouse-detailed",
        redirect: "/warehouse/in-warehouse/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          title: "在库管理",
          requireAuth: true
        },
        children: [
          {
            path: "/warehouse/in-warehouse/details",
            name: "in-warehouse-details",
            component: () => import("@/views/warehouse/in-warehouse/details"),
            meta: {
              title: "入库管理详情",
              requireAuth: true
            }
          }
        ]
      }
    ]
  },
  //系统配置
  {
    path: "/resourceManage",
    component: Layout,
    redirect: "/resourceManage/port",
    meta: {
      keepAlive: false,
      title: "系统配置",
      requireAuth: true
    },
    children: [
      {
        path: "/resourceManage/port",
        name: "port-index",
        component: () => import("@/views/resourceManage/port/index"),
        meta: {
          title: "港口配置",
          requireAuth: true
        }
      },
      {
        path: "/resourceManage/vehicleInfo",
        name: "vehicleInfo-index",
        component: () => import("@/views/resourceManage/vehicleInfo/index"),
        meta: {
          title: "车辆配置",
          requireAuth: true
        }
      },
      {
        path: "/resourceManage/brand",
        name: "brand-index",
        component: () => import("@/views/resourceManage/brand/index"),
        meta: {
          title: "品牌配置",
          requireAuth: true
        }
      },
      {
        path: "/resourceManage/expense",
        name: "expense-index",
        component: () => import("@/views/resourceManage/expense/index"),
        meta: {
          title: "费用配置",
          requireAuth: true
        }
      },
      {
        path: "/resourceManage/company",
        name: "company",
        component: () => import("@/views/resourceManage/company/index"),
        meta: {
          title: "平台企业配置",
          requireAuth: true
        }
      }
    ]
  },
  //会员配置
  {
    path: "/member",
    component: Layout,
    redirect: "/member/setting/index",
    meta: {
      keepAlive: false,
      title: "会员管理",
      requireAuth: true
    },
    children: []
  },
  //权限管理
  {
    path: "/userManage",
    name: "center",
    redirect: "/resourceManage/role",
    component: Layout,
    meta: {
      keepAlive: false,
      title: "权限管理"
    },
    children: [
      {
        path: "/resourceManage/role",
        name: "setting-index",
        component: () => import("@/views/resourceManage/role/index"),
        meta: {
          title: "角色管理",
          requireAuth: true
        }
      },
      {
        path: "/resourceManage/user",
        name: "setting-index",
        component: () => import("@/views/resourceManage/role/user"),
        meta: {
          title: "用户管理",
          requireAuth: true
        }
      },
      {
        path: "/resourceManage/authMenu",
        name: "authMenu",
        component: () => import("@/views/resourceManage/role/authMenu"),
        meta: {
          title: "授权菜单",
          requireAuth: true
        }
      },
      {
        path: "/resourceManage/log",
        name: "log",
        component: () => import("@/views/resourceManage/role/log"),
        meta: {
          title: "操作日志",
          requireAuth: true
        }
      }
    ]
  },
  //  贷款管理
  {
    path: "/loan",
    component: Layout,
    redirect: "/loan/index",
    meta: {
      title: "贷款管理",
      requireAuth: true
    },
    children: [
      {
        path: "/loan",
        name: "loan-index",
        component: () => import("@/views/loan/index"),
        meta: {
          keepAlive: true,
          title: "贷款管理",
          requireAuth: true
        }
      },
      {
        path: "/loan/detailed",
        name: "loan-detailed",
        redirect: "/loan/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          title: "贷款账单",
          requireAuth: true
        },
        children: [
          {
            path: "/loan/details",
            name: "loan-details",
            component: () => import("@/views/loan/details"),
            meta: {
              title: "贷款详情",
              requireAuth: true
            }
          }
        ]
      },
      {
        path: "/loan/marginBill",
        name: "loan-marginBill",
        component: () => import("@/views/loan/marginBill"),
        meta: {
          keepAlive: true,
          title: "保证金账单",
          requireAuth: true
        }
      },
      {
        path: "/loan/marginBill/detailed",
        name: "marginBill-detailed",
        redirect: "/loan/marginBill/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          title: "保证金账单详情",
          requireAuth: true
        },
        children: [
          {
            path: "/loan/marginBill/details",
            name: "marginBill-details",
            component: () => import("@/views/loan/marginBill/details"),
            meta: {
              title: "保证金账单详情",
              requireAuth: true
            }
          }
        ]
      },
      {
        path: "/loan/exportMargin",
        name: "loan-exportMargin",
        component: () => import("@/views/loan/exportMargin"),
        meta: {
          keepAlive: true,
          title: "出口保证金账单",
          requireAuth: true
        }
      },
      {
        path: "/loan/exportMargin/detailed",
        name: "exportMargin-detailed",
        redirect: "/loan/exportMargin/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          title: "出口保证金账单",
          requireAuth: true
        },
        children: [
          {
            path: "/loan/exportMargin/details",
            name: "exportMargin-details",
            component: () => import("@/views/loan/exportMargin/details"),
            meta: {
              title: "出口保证金账单详情",
              requireAuth: true
            }
          }
        ]
      }
    ]
  },
  //结算管理
  {
    path: "/settlement",
    component: Layout,
    redirect: "/settlement/carBill",
    meta: {
      title: "结算管理",
      requireAuth: true
    },
    children: [
      {
        //四期
        path: "/settlement/carBill",
        name: "settlement-carBill",
        component: () => import("@/views/settlement/carBill"),
        meta: {
          keepAlive: true,
          title: "进口商账单",
          requireAuth: true
        }
      },
      {
        //四期
        path: "/settlement/carBill/detailed",
        name: "carBill-detailed",
        redirect: "/settlement/carBill/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          keepAlive: false,
          title: "进口商账单",
          requireAuth: true
        },
        children: [
          {
            path: "/settlement/carBill/details",
            name: "carBill-details",
            component: () => import("@/views/settlement/carBill/details"),
            meta: {
              title: "进口商账单详情",
              requireAuth: true
            }
          }
        ]
      },
      {
        //三期
        path: "/settlement/billList",
        name: "settlement-billList",
        component: () => import("@/views/settlement/billList"),
        meta: {
          keepAlive: true,
          title: "账单管理",
          requireAuth: true
        }
      },
      {
        //三期
        path: "/settlement/vehiclePayment",
        name: "settlement-vehiclePayment",
        component: () => import("@/views/settlement/vehiclePayment"),
        meta: {
          keepAlive: true,
          title: "车款结算",
          requireAuth: true
        }
      },
      {
        //三期
        path: "/settlement/vehiclePayment/detailed",
        name: "vehiclePayment-detailed",
        redirect: "/settlement/vehiclePayment/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          keepAlive: false,
          title: "车款结算",
          requireAuth: true
        },
        children: [
          {
            path: "/settlement/vehiclePayment/details",
            name: "vehiclePayment-details",
            component: () =>
              import("@/views/settlement/vehiclePayment/details"),
            meta: {
              title: "车款结算详情",
              requireAuth: true
            }
          }
        ]
      },
      {
        //三期
        path: "/settlement/tax",
        name: "settlement-tax",
        component: () => import("@/views/settlement/tax"),
        meta: {
          keepAlive: true,
          title: "退税结算",
          requireAuth: true
        }
      }
    ]
  },
  //手续管理
  {
    path: "/procedures/car",
    component: Layout,
    redirect: "/procedures/car/index",
    meta: {
      title: "手续管理",
      requireAuth: true
    },
    children: [
      {
        path: "/procedures/car",
        name: "proceduresCar-index",
        component: () => import("@/views/procedures/car/index"),
        meta: {
          keepAlive: true,
          title: "车辆手续管理",
          requireAuth: true
        }
      },
      {
        path: "/procedures/car/detailed",
        name: "proceduresCar-detailed",
        redirect: "/procedures/car/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          keepAlive: false,
          title: "车辆手续",
          requireAuth: true
        },
        children: [
          {
            path: "/procedures/car/details",
            name: "proceduresCar-details",
            component: () => import("@/views/procedures/car/details"),
            meta: {
              title: "车辆手续详情",
              requireAuth: true
            }
          }
        ]
      },
      {
        //三期
        path: "/procedures/export",
        name: "proceduresExport-index",
        component: () => import("@/views/procedures/export/index"),
        meta: {
          keepAlive: true,
          title: "出口手续管理",
          requireAuth: true
        }
      },
      {
        path: "/procedures/export/detailed",
        name: "proceduresExport-detailed",
        redirect: "/procedures/export/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          keepAlive: false,
          title: "出口手续详情",
          requireAuth: true
        },
        children: [
          {
            path: "/procedures/export/details",
            name: "proceduresExport-details",
            component: () => import("@/views/procedures/export/details"),
            meta: {
              title: "出口手续详情",
              requireAuth: true
            }
          }
        ]
      },
      {
        //三期
        path: "/procedures/customsEntry",
        name: "proceduresCustomsEntry-index",
        component: () => import("@/views/procedures/customsEntry/index"),
        meta: {
          keepAlive: true,
          title: "报关单管理",
          requireAuth: true
        }
      },
      {
        //三期
        path: "/procedures/withdraw",
        name: "proceduresWithdraw-index",
        component: () => import("@/views/procedures/withdraw/index"),
        meta: {
          keepAlive: true,
          title: "车辆注销管理",
          requireAuth: true
        }
      }
    ]
  },
  //资方管理
  {
    path: "/capital",
    component: Layout,
    redirect: "/capital/security/index",
    meta: {
      title: "结算管理",
      requireAuth: true
    },
    children: [
      {
        path: "/capital/security",
        name: "capital-security",
        component: () => import("@/views/capital/security"),
        meta: {
          keepAlive: true,
          title: "担保管理",
          requireAuth: true
        }
      },
      {
        path: "/capital/security/detailed",
        name: "security-detailed",
        redirect: "/capital/security/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          keepAlive: false,
          title: "担保管理",
          requireAuth: true
        },
        children: [
          {
            path: "/capital/security/details",
            name: "security-details",
            component: () => import("@/views/saleOrder/details"),
            meta: {
              title: "担保管理详情",
              requireAuth: true
            }
          }
        ]
      },
      {
        path: "/capital/bank",
        name: "capital-bank",
        component: () => import("@/views/capital/bank"),
        meta: {
          keepAlive: true,
          title: "银行管理",
          requireAuth: true
        }
      },
      {
        path: "/capital/bank/detailed",
        name: "bank-detailed",
        redirect: "/capital/bank/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          keepAlive: false,
          title: "银行管理",
          requireAuth: true
        },
        children: [
          {
            path: "/capital/bank/details",
            name: "bank-details",
            component: () => import("@/views/saleOrder/details"),
            meta: {
              title: "审批详情",
              requireAuth: true
            }
          }
        ]
      }
    ]
  },
  //销售出口管理
  {
    path: "/saleOrder",
    component: Layout,
    redirect: "/saleOrder/index",
    meta: {
      title: "销售申请管理",
      requireAuth: true
    },
    children: [
      {
        path: "/saleOrder",
        name: "saleOrder-index",
        component: () => import("@/views/saleOrder"),
        meta: {
          keepAlive: true,
          title: "销售申请管理",
          requireAuth: true
        }
      },
      {
        path: "/saleOrder/detailed",
        name: "saleOrder-detailed",
        redirect: "/saleOrder/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          keepAlive: false,
          title: "销售申请管理",
          requireAuth: true
        },
        children: [
          {
            path: "/saleOrder/details",
            name: "saleOrder-details",
            component: () => import("@/views/saleOrder/details"),
            meta: {
              title: "销售申请详情",
              requireAuth: true
            }
          }
        ]
      }
    ]
  },

  //四期
  //交易订单管理
  {
    path: "/tradeOrder/order",
    component: Layout,
    redirect: "/tradeOrder/order/index",
    meta: {
      title: "交易订单管理",
      requireAuth: true
    },
    children: [
      {
        path: "/tradeOrder/order",
        name: "order-index",
        component: () => import("@/views/tradeOrder/order"),
        meta: {
          keepAlive: true,
          title: "订单管理",
          requireAuth: true
        }
      },
      {
        path: "/tradeOrder/order/detailed",
        name: "order-detailed",
        redirect: "/tradeOrder/order/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          keepAlive: false,
          title: "订单管理",
          requireAuth: true
        },
        children: [
          {
            path: "/tradeOrder/order/details",
            name: "order-details",
            component: () => import("@/views/tradeOrder/order/details"),
            meta: {
              title: "订单详情",
              requireAuth: true
            }
          }
        ]
      },
      {
        path: "/tradeOrder/shipmentApply",
        name: "shipmentApply-index",
        component: () => import("@/views/tradeOrder/shipmentApply"),
        meta: {
          keepAlive: true,
          title: "发货申请",
          requireAuth: true
        }
      },
      {
        path: "/tradeOrder/shipmentApply/detailed",
        name: "shipmentApply-detailed",
        redirect: "/tradeOrder/shipmentApply/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          keepAlive: false,
          title: "发货申请",
          requireAuth: true
        },
        children: [
          {
            path: "/tradeOrder/shipmentApply/details",
            name: "order-details",
            component: () => import("@/views/tradeOrder/shipmentApply/details"),
            meta: {
              title: "发货申请详情",
              requireAuth: true
            }
          }
        ]
      },
      {
        path: "/tradeOrder/pick",
        name: "pick-index",
        component: () => import("@/views/tradeOrder/pick"),
        meta: {
          keepAlive: false,
          title: "提车申请",
          requireAuth: true
        }
      }
    ]
  },
  //三期
  //车辆上架审核
  {
    path: "/listingReview",
    component: Layout,
    redirect: "/listingReview/index",
    meta: {
      title: "车辆上架审核",
      requireAuth: true
    },
    children: [
      {
        path: "/listingReview",
        name: "listingReview-index",
        component: () => import("@/views/listingReview"),
        meta: {
          keepAlive: true,
          title: "车辆上架审核",
          requireAuth: true
        }
      },
      {
        path: "/listingReview/detailed",
        name: "listingReview-detailed",
        redirect: "/listingReview/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          keepAlive: false,
          title: "车辆上架审核",
          requireAuth: true
        },
        children: [
          {
            path: "/listingReview/details",
            name: "listingReview-details",
            component: () => import("@/views/listingReview/details"),
            meta: {
              title: "车辆上架审核详情",
              requireAuth: true
            }
          }
        ]
      }
    ]
  },
  //出口申请管理 四期
  {
    path: "/exportOrder",
    component: Layout,
    redirect: "/exportOrder/index",
    meta: {
      title: "出口申请管理",
      requireAuth: true
    },
    children: [
      {
        path: "/exportOrder",
        name: "exportOrder-index",
        component: () => import("@/views/exportOrder"),
        meta: {
          keepAlive: true,
          title: "出口申请管理",
          requireAuth: true
        }
      },
      {
        path: "/exportOrder/detailed",
        name: "exportOrder-detailed",
        redirect: "/saleOrder/detailed",
        component: {
          render(c) {
            return c("router-view");
          }
        },
        meta: {
          keepAlive: false,
          title: "出口申请管理",
          requireAuth: true
        },
        children: [
          {
            path: "/exportOrder/details",
            name: "exportOrder-details",
            component: () => import("@/views/exportOrder/details"),
            meta: {
              title: "出口申请详情",
              requireAuth: true
            }
          }
        ]
      }
    ]
  }
];
// 开启
//重复进入路由不报错
// const originalPush = Router.prototype.push
// Router.prototype.push = function push(location) {
//     return originalPush.call(this, location).catch(err => err)
// }
export const createRouter = () => {
  let router = new Router({ routes: originRoutes });
  return router;
};
let router = createRouter();
export const resetRouter = () => {
  let newRouter = createRouter();
  router.matcher = newRouter.matcher;
};
export default router;
